<template>
    <div>
        <Modal v-model="modals" :z-index="100" scrollable  footer-hide closable title="发送卡包" :mask-closable="false" width="900">
            <div class="acea-row">
                <span class="sp">卡包名称：</span><Input v-model="page.coupon_title" search enter-button placeholder="请输入卡包名称" style="width: 60%;"  @on-search="userSearchs"/>
            </div>
            <Table  :columns="columns" :data="couponList" ref="table" class="mt25"
                    :loading="loading" highlight-row
                    no-userFrom-text="暂无数据"
                    no-filtered-userFrom-text="暂无筛选结果">
                <template slot-scope="{ row }" slot="type">
                    <span v-if="row.type === 1">闺蜜卡包</span>
                    <span v-else-if="row.type === 2">权益卡包</span>
                    <span v-else-if="row.type === 3">抽奖卡包</span>
                    <span v-else-if="row.type === 4">商品卡包</span>
                    <span v-else-if="row.type === 5">生日卡包</span>
                </template>
                <template slot-scope="{ row }" slot="begin_time">
                    <div>
                        {{ row.begin_time}} - {{ row.end_time}}
                    </div>
                </template>
                <template slot-scope="{ row, index }" slot="action">
                    <a @click="sendGrant(row.pid,row.title)">添加</a>
                </template>
            </Table>
            <div class="acea-row row-right page">
                <Page :total="total" show-elevator show-total   @on-change="pageChange"
                      :page-size="page.limit"  /></div>
        </Modal>
    </div>
</template>

<script>
    import { cardListApi } from "@/api/marketing";
    export default {
        name: 'card',
        props: {},
        created(){},
        data () {
            return {
                modals: false,
                loading: false,
                couponList: [],
                columns: [
                    {
                        title: '卡包名称',
                        key: 'title',
                        align: 'center',
                        minWidth: 100
                    },
                    {
                        title: "卡包类型",
                        slot: "type",
                        align: 'center',
                        minWidth: 80,
                    },
                    {
                        title: "使用时间段",
                        slot: "begin_time",
                        minWidth: 250,
                        align: "center"
                    },
                    {
                        title: '操作',
                        slot: 'action',
                        align: 'center',
                        width: 120
                    }
                ],
                page: {
                    page: 1, // 当前页
                    limit: 15,
                    coupon_title: '',
                    type: 'send'
                },
                total: 0 // 总条数
            }
        },
        methods: {
            // 卡包列表
            getList () {
                this.loading = true;
                cardListApi({
                    is_show: 1,
                    type: 4,
                }).then(async res => {
                    if (res.status === 200) {
                        let data = res.data
                        this.couponList = data.list;
                        this.total = data.count;
                        this.loading = false;
                    } else {
                        this.loading = false;
                        this.$Message.error(res.msg);
                    }
                }).catch(res => {
                    this.loading = false;
                    this.$Message.error(res.msg);
                })
            },
            // 表格搜索
            userSearchs () {
                this.getList();
            },
            pageChange (index) {
                this.page.page = index;
                this.getList();
            },
            // 发送
            sendGrant (pid,title) {
                let data = [{
                    pid: pid,
                    title: title
                }]
                this.$emit('cardHolder', data)
            }
        }
    }
</script>

<style scoped lang="stylus">
    .sp
        line-height 32px

</style>
